<?php


namespace App\helper;


use App\Enum\BooleanEnum;

class WebResp
{

    protected static array $resp = [
        'data'=>null,
        'message'=>'',
        'state'=>BooleanEnum::YES,
    ];
    public static function success($msg='',$data=null){
        self::$resp['message'] = $msg;
        self::$resp['data'] = $data;
        return self::send();
    }
    public static function error($msg='',$data=null,int $status = 200){
        self::$resp['message'] = $msg;
        self::$resp['data'] = $data;
        self::$resp['state'] = BooleanEnum::NO;
        return self::send($status);
    }
    public static function data($data=[]){
        self::$resp['data'] = $data;
        return self::send();
    }
    protected static function send(int $status = 200){
       return \response()->json(self::$resp,$status);
    }
}
